/*
 * @Description: app Mutations
 * @Author: ZY
 * @Date: 2020-12-23 10:25:37
 * @LastEditors: ZY
 * @LastEditTime: 2020-12-28 11:45:02
 */
import { MutationTree } from 'vuex'
import { UserState } from './state'
import { UserMutationTypes } from './mutation-types'
import { TableDetail } from '@/types/setting/data-source';

export type Mutations<S = UserState> = {
  [UserMutationTypes.SET_TOKEN](state: S, token: string): void
  [UserMutationTypes.SET_REFRESH_TOKEN](state: S, refresh_token: string): void
  [UserMutationTypes.SET_NAME](state: S, name: string): void
  [UserMutationTypes.SET_AVATAR](state: S, avatar: string): void
  [UserMutationTypes.SET_INTRODUCTION](state: S, introduction: string): void
  [UserMutationTypes.SET_ROLES](state: S, roles: string[]): void
  [UserMutationTypes.SET_ROUTER_LIST](state: S, routerList: string[]): void
  [UserMutationTypes.IS_ADMIN](state: S, isAdmin: boolean): void
  [UserMutationTypes.TENANT_NAME](state: S, tenantName: string): void
  [UserMutationTypes.CURRENT_USER](state: S, currentUser: object): void
  [UserMutationTypes.SET_EMAIL](state: S, email: string): void
  [UserMutationTypes.SET_CURRENT_DATA_SOURCE](state: S, currentDataSource: object): void
  [UserMutationTypes.SET_IS_SHOW_COLOR](state: S, isShowColors: boolean): void
  [UserMutationTypes.SET_JUMP_LOADING](state: S, jumpLoading: boolean): void
  [UserMutationTypes.SET_BREAD_CRUMB_LIST](state: S, breadcrumbList: any): void
  [UserMutationTypes.changeLang](state: S, params: any): void
  [UserMutationTypes.bread](state: S, bread: any): void
  [UserMutationTypes.splice](state: S, bread: any): void
}

export const mutations: MutationTree<UserState> & Mutations = {
  [UserMutationTypes.SET_TOKEN](state: UserState, token: string) {
    state.token = token
  },

  [UserMutationTypes.SET_REFRESH_TOKEN](state: UserState, refreshToken: string) {
    state.refreshToken = refreshToken
  },

  [UserMutationTypes.SET_NAME](state: UserState, name: string) {
    state.name = name
  },

  [UserMutationTypes.SET_AVATAR](state: UserState, avatar: string) {
    state.avatar = avatar
  },

  [UserMutationTypes.SET_INTRODUCTION](state: UserState, introduction: string) {
    state.introduction = introduction
  },

  [UserMutationTypes.SET_ROLES](state: UserState, roles: string[]) {
    state.roles = roles
  },

  [UserMutationTypes.SET_ROUTER_LIST](state: UserState, routerList: string[]) {
    state.routerList = routerList
  },

  [UserMutationTypes.IS_ADMIN](state: UserState, isAdmin: boolean) {
    state.isAdmin = isAdmin
  },

  [UserMutationTypes.TENANT_NAME](state: UserState, tenantName: string) {
    state.tenantName = tenantName
  },

  [UserMutationTypes.CURRENT_USER](state: UserState, currentUser: string[]) {
    state.currentUser = currentUser
  },



  [UserMutationTypes.SET_EMAIL](state: UserState, email: string) {
    state.email = email
  },

  [UserMutationTypes.SET_CURRENT_DATA_SOURCE](state: UserState, currentDataSource: TableDetail) {
    state.currentDataSource = currentDataSource
  },

  [UserMutationTypes.SET_IS_SHOW_COLOR](state: UserState, isShowColors: boolean) {
    state.isShowColors = isShowColors
  },
  [UserMutationTypes.SET_JUMP_LOADING](state: UserState, jumpLoading: boolean) {
    console.log(jumpLoading);

    state.jumpLoading = jumpLoading
  },

  [UserMutationTypes.SET_BREAD_CRUMB_LIST](state: UserState, breadcrumbList: any) {
    state.breadcrumbList = breadcrumbList
  },
  [UserMutationTypes.changeLang](state: UserState, lang: any) {
    state.lang = lang
    sessionStorage.setItem('lang',lang)
  },
  [UserMutationTypes.bread](state: UserState, bread: any) {
    state.bread.push(bread)
  },
  [UserMutationTypes.splice](state: UserState, splice: any) {
    state.bread.splice(splice,1)
  }
}
